 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package TDJsp;

import java.sql.*;
import java.util.Hashtable;
import java.util.Properties;
import java.util.ArrayList;
import java.util.*;
import java.lang.String;



/**
 *
 * @author zouafr
 */
public class BD {
       

   private ArrayList<DVD> arrList;
         
   public BD()
   {
        try {
           
            Class.forName("oracle.jdbc.driver.OracleDriver");
        }
        catch( Exception ex ) {
            System.err.println( "Erreur lors du chargement du driver" );
            System.exit(1);
        }
        try{
            /** Connection à la base - Étape 2 */
            String url="jdbc:oracle:thin:@miage03.dmiage.u-paris10.fr:1521:MIAGE";
            Connection cx = DriverManager.getConnection (url, "zouafr", "apprentis2012pw");
            /** Création et exécution d'une requête - Étapes 3 & 4 */
            Statement st = cx.createStatement();
            ResultSet rs = st.executeQuery( "SELECT * FROM catalogue" );
            /** Affichage du résultat - Étape 5 */
 
            System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");   
            arrList = new ArrayList<DVD>();
            while (rs.next()) {
                System.out.println("YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY");
                String desc = rs.getString("DESCRIPTION");
                float prix= rs.getFloat("PRIX");
                
                
                DVD monDvd= new DVD(desc, prix);
                //monDvd.toString();
                //System.out.println(monDvd);
                arrList.add(monDvd);
                
               
                System.out.println("description :" + desc + "prix" + prix );
            }
        
            /** Fermetures - Étape 6 */
            rs.close();
            st.close();
            cx.close();
        }
        catch( SQLException ex ) {
            System.out.println( "Erreur lors de la cx à la base"+ex );
            System.exit(1);
        }
   }

   public void afficher()
   {

        Iterator<DVD> monIt = this.arrList.iterator();
              while(monIt.hasNext())
               {
                   DVD d = monIt.next();
                   d.toString();
               }

   }
    public ArrayList<DVD> getArrList() {
        return arrList;
    }
    
    
}
   
    

